package DAO;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

import Beans.SmsStatus;
import Utils.HibernateUtil;

public class SmsStatusDao {
	private SessionFactory sessionFactory;

	public SmsStatusDao() {
		sessionFactory = HibernateUtil.getSessionFactory();
	}

	Transaction tr = null;
	
	
	/**
	 * 返回所有代理商信息
	 */
	public List<SmsStatus> getAllSmsStatus(int status){
		Session session=sessionFactory.openSession();
		tr=session.beginTransaction();
		Criteria c=session.createCriteria(SmsStatus.class);
		if(status==0){
			c.add(Restrictions.ne("status", 1));
		}
		if(status==1){
			c.add(Restrictions.eq("status", status));
		}
		List<SmsStatus> smsStatus=c.list();
		tr.commit();
		session.close();
		return smsStatus;
	}
	
	/**
	 * 通过代理商ID返回指定代理商信息
	 * 
	 * @return
	 */
	public SmsStatus getSmsStatusById(int smsStatusId) {
		Session session = sessionFactory.openSession();
		tr = session.beginTransaction();
		SmsStatus smsStatus = (SmsStatus) session.get(SmsStatus.class, smsStatusId);
		tr.commit();
		session.close();
		return smsStatus;
	}

	/**
	 * 获取该包裹的短信发送详情
	 * @param parcelID
	 * @return
	 */
	public List<SmsStatus> getByParcelID(int parcelID) {
		Session session=sessionFactory.openSession();
		tr=session.beginTransaction();
		Criteria c=session.createCriteria(SmsStatus.class);
		c.add(Restrictions.eq("packageId", (long)parcelID));
		List<SmsStatus> smsStatus=c.list();
		tr.commit();
		session.close();
		return smsStatus;
	}
}
